<?php

namespace app\controller;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use think\facade\Log;

class Crawler {
    public function guzzle() : string
    {
        //要访问的目标页面
        $page_url = "http://v2.api.juliangip.com/v2/dps/ip_search";
        $client = new Client();
        $options = [
            'proxy'   => [
                'http'  => 'http://c323b38383469da7:257037724565111@117.90.15.115:34006',
                'https' => 'http://c323b38383469da7:257037724565111@117.90.15.115:34006',
            ],
            'connect_timeout' => 3,
            'timeout' => 10,
        ];
        
        //发送GET请求
        try {
            $res = $client->request('GET', $page_url, $options);
            $body = $res->getBody();
            return $body->getContents();
        } catch (GuzzleException $e) {
            Log::error($e->getMessage());
            return $e->getMessage();
        }
    }
}